/*
 * Copyright (C) 2013 Andreas Stuetz <andreas.stuetz@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bingkaimedia.merchantbeta.app;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.bingkaimedia.merchantbeta.R;
import com.bingkaimedia.merchantbeta.libs.JSONfunctions;
import com.bingkaimedia.merchantbeta.libs.LazyAdapter2;
import com.bingkaimedia.merchantbeta.libs.SessionManager;
import com.bingkaimedia.merchantbeta.libs_slidemenu.BaseActivity;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;


@SuppressLint("NewApi")
public class My_Voucher extends BaseActivity {
 
		
	int current_page = 0;
	

	// XML node keys
	//static final String KEY_SONG = "song"; // parent node
	public static final String KEY_VOUCHER_ID = "voucher_id";
	public static final String KEY_VOUCHER_NAME = "voucher_name"; 
	public static final String KEY_CHANNEL_NAME = "channel_name"; 
	public static final String KEY_VOUCHER_TOTAL = "voucher_total";
	public static final String KEY_VOUCHER_TERSEDIA = "voucher_tersedia";
	public static final String KEY_VOUCHER_DETAIL = "voucher_detail";
	public static final String KEY_VOUCHER_DATE = "voucher_date";
	public static final String KEY_VOUCHER_DESCRIPTION = "voucher_description";
	public static final String KEY_MERCHANT_ID = "merchant_id";
	public static final String KEY_MERCHANT_NAME = "merchant_name";
	public static final String KEY_MERCHANT_CATEGORY = "merchant_category";
	public static final String KEY_MERCHANT_PHOTO = "merchant_photo";
	public static final String KEY_TRANSACTION_ID = "transaction_id";
	public static final String KEY_TRANSACTION_DATE = "transaction_date";
	public static final String KEY_TRANSACTION_IMAGE = "transaction_image";
	public static final String KEY_TRANSACTION_STATUS = "transaction_status";
	 
	
	private String xml_voucher_id;
	private String xml_voucher_name;
	private String xml_voucher_total;
	private String xml_voucher_tersedia;
	private String xml_voucher_description;
	private String xml_voucher_detail;
	private String xml_voucher_date;
	private String xml_merchant_id;
	private String xml_merchant_name;
	private String xml_channel_name;
	private String xml_merchant_category;
	private String xml_merchant_photo;
	private String xml_transaction_id;
	private String xml_transaction_date;
	private String xml_transaction_image;
	private String xml_transaction_status;
	
	private static String session_userid;
	private static String session_username;
	private static String session_password;
	private static String session_email;
	private static String session_country;
	private static String session_country_name; 
	private static String session_city;
	private static String session_city_name;
	private static String session_checked;
	private static String session_channel;
	private static String session_category;
	private static String session_category_name;
    
	//String keyno;
	
	//TextView jumlahsaldo,key_nohp;
	//private String url = Global.url_global + "get_list_transaksi.php?nohp=";
	
	//private Button load_more;
	//private String jsonResult;

	// Session Manager Class
	SessionManager session;
	
	private LazyAdapter2 adapter;
	ArrayList<HashMap<String, String>> menuItems;
	ProgressDialog pDialog;
	HashMap<String, String> map = new HashMap<String, String>();
	
	ArrayList<HashMap<String, String>> diskonba_list = new ArrayList<HashMap<String, String>>();
	
	//ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
	
	//slide menu
	private LinearLayout slidingPanel;
	private boolean isExpanded;
	private DisplayMetrics metrics;
	private RelativeLayout headerPanel;
	private int panelWidth;
	private int panelWidth1;
	private Button btnLoadMore;
	public static String sta="";
	
	private ImageView menuViewButton,menuRightButton;
	
	
	private PullToRefreshListView mPullRefreshListView;
	ListView actualListView;
	

	private int count;
	private String json;
	private String result;
	private JSONObject jsonobject;
	public String code;
	public String msg;
	
	FrameLayout.LayoutParams menuPanelParameters;
	FrameLayout.LayoutParams slidingPanelParameters;
	LinearLayout.LayoutParams headerPanelParameters;
	LinearLayout.LayoutParams listViewParameters;
 
	private SlidingMenu sm;
	 
	public My_Voucher() {
		super(R.string.baru); 
	}


	@Override
	public void onBackPressed() { 
		My_Voucher.this.finish();
	}
	
	@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
    }
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_voucher);
		overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
		
		fungsi_menu();
		
		deklarasi_refresh();
		
		deklarasi_list();
				
		new loadListView().execute();
	 
		aksi_klik();			 


		String result = null;
		InputStream is = null;
		StringBuilder sb=null; 

		ArrayList nameValuePairs = new ArrayList();
 
				
 
	}
 

	public void fungsi_menu(){
		
		setSlidingActionBarEnabled(true);
		 
        sm = getSlidingMenu();
		 
		LinearLayout header_vertical_divider_1 = (LinearLayout) findViewById(R.id.header_vertical_divider_1);
		LinearLayout header_vertical_divider_2 = (LinearLayout) findViewById(R.id.header_vertical_divider_2);
		ImageView diskonion_iconmenu = (ImageView) findViewById(R.id.diskonion_iconmenu);
		ImageView diskonion_iconhome = (ImageView) findViewById(R.id.diskonion_iconhome);
		ImageView diskonion_iconsearch = (ImageView) findViewById(R.id.diskonion_iconsearch);
		ImageView diskonion_iconcategory = (ImageView) findViewById(R.id.diskonion_iconcategory);
		
		 
		
		diskonion_iconmenu.setOnClickListener(new OnClickListener() { 
	 			public void onClick(View v)  {
				sm.showMenu(); 
			}
		}); 
		
		diskonion_iconhome.setOnClickListener(new OnClickListener() { 
	 			public void onClick(View v)  {
				//sm.showSecondaryMenu();
 				Intent intent=new Intent(getApplicationContext(),Home.class);
 				startActivity(intent);
			}
		});
		
		diskonion_iconsearch.setOnClickListener(new OnClickListener() { 
	 			public void onClick(View v)  {
				//sm.showSecondaryMenu();
 				Intent intent=new Intent(getApplicationContext(),Search.class);
 				startActivity(intent);
			}
		});
		
		diskonion_iconcategory.setOnClickListener(new OnClickListener() { 
	 			public void onClick(View v)  {
				sm.showSecondaryMenu(); 
			}
		});
 		
	}
	
	public void deklarasi_refresh(){
		//loading
		mPullRefreshListView = (PullToRefreshListView)findViewById(R.id.pull_refresh_list);

		mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
			@Override
			public void onRefresh(PullToRefreshBase<ListView> refreshView) {
				String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
						DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
 
				refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); 
				new loadMoreListView().execute();
			}
		}); 
  
		mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { 
			@Override
			public void onLastItemVisible() {
				//Toast.makeText(FragmentSenin.this.getActivity(), "End of List!", Toast.LENGTH_SHORT).show();
			}
		});
			
		actualListView = mPullRefreshListView.getRefreshableView();
 
		registerForContextMenu(actualListView);
		
		
		//sound
		/*
		SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(FragmentSenin.this.getActivity());
		soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);
		soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);
		soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);
		mPullRefreshListView.setOnPullEventListener(soundListener);
		*/
		
		//variasi
		mPullRefreshListView.setMode(mPullRefreshListView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START: Mode.BOTH);
		//mPullRefreshListView.setRefreshing(false);
		//mPullRefreshListView.setScrollingWhileRefreshingEnabled(!mPullRefreshListView.isScrollingWhileRefreshingEnabled());
		//mPullRefreshListView.demo();		
	}
	
	
	
	
	public void deklarasi_list(){ 
		
		session = new SessionManager(getApplicationContext());
	    
	    HashMap<String, String> user = session.getUserDetails();
	     
	    // name
	    session_userid = user.get(SessionManager.id_users);
	    session_username = user.get(SessionManager.username);
	    session_password = user.get(SessionManager.password);
	    session_email = user.get(SessionManager.email);
	    session_country = user.get(SessionManager.country);
	    session_country_name = user.get(SessionManager.country_name);
	    session_city = user.get(SessionManager.city);
	    session_city_name = user.get(SessionManager.city_name);
	    session_checked = user.get(SessionManager.checked);
	    session_channel = user.get(SessionManager.channel);
	    session_category = user.get(SessionManager.category);
	    session_category_name = user.get(SessionManager.category_name);
	    
	    //System.out.println("session");
	    //System.out.println(session_userid);
	    //System.out.println(session_username);
	    //System.out.println(session_password);
	    //System.out.println(session_email);
	    //System.out.println(session_country);
	    //System.out.println(session_country_name);
	    //System.out.println(session_city);
	    //System.out.println(session_city_name);
	    //System.out.println(session_checked);
	    //System.out.println(session_channel);
	    //System.out.println(session_category);
	    //System.out.println(session_category_name);
	     
	     
	    /*
	    TextView city_category = (TextView)findViewById(R.id.city_category);
	    if (session_category == "")
	    {
	    	city_category.setText(session_city_name + " - " + "[ ALL ]");
	    }
	    else
	    {
	    	city_category.setText(session_city_name + " - " + "[ " + session_category_name +" ]");
	    }
	    */
	}
	
	
	
	public void aksi_klik(){
		
		actualListView.setOnItemClickListener(new OnItemClickListener() { 
			@Override
			public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
							// getting values from selected ListItem
				String list_id = ((TextView) view.findViewById(R.id.txt_transaction_id))
						.getText().toString();

				// Starting new intent
				Intent in = new Intent(getApplicationContext(),
						My_Voucher_Detail.class);
				in.putExtra(KEY_TRANSACTION_ID, list_id);
				startActivity(in);
				//My_Voucher.this.finish();
			}
		});  
		
		 
		 
	}
	
	
	@SuppressLint("NewApi")
	private class loadListView extends AsyncTask<Void, Void, Void>  {

		@Override
		protected void onPreExecute() {
			// Showing progress dialog before sending http request
			pDialog = new ProgressDialog(
					My_Voucher.this);
			pDialog.setMessage("Retrieve Data, Please wait...");
			pDialog.setIndeterminate(true);
			pDialog.setCancelable(false);
			pDialog.show();
		}

		protected Void doInBackground(Void... unused) {
			//runOnUiThread(new Runnable() {
			//	public void run() {
			// increment current page
			 
			
			//ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
			
			String result = null;
			InputStream is = null;
			StringBuilder sb=null; 

			ArrayList nameValuePairs = new ArrayList();
			
			
			 
		    
			// Next page request
			Global.URL = Global.link_my_voucher + session_userid + "&page=" + current_page;
			//System.out.println(Global.URL); 
			
			
			Global.URL = Global.URL.replace(" ", "%20");
			code="99";
			msg="Not connected to server";
			
			//System.out.println("Mulai do in background");
			try{ 
				json=JSONfunctions.getStringContent(Global.URL);
				jsonobject=new JSONObject(json); 
				code=jsonobject.getString("code");
				msg=jsonobject.getString("msg");
				 
			}
			catch (Exception e) 
			{
				e.printStackTrace();
				System.out.println("catch code msg");
				System.out.println(e);
				//pDialog.dismiss();
				//Toast.makeText(getApplicationContext(), "Something wrong in your connection", Toast.LENGTH_LONG).show();
			
			}
			
			System.out.println("code "+code);
			if(code.equalsIgnoreCase("99")){
				try{ 
					System.out.println(Global.URL);
					//json=JSONfunctions.getStringContent2(Global.URL);
					System.out.println(json); 
					 
				}
				catch (Exception e) 
				{
					e.printStackTrace();
					System.out.println("catch 1");
					System.out.println(e);

					//pDialog.dismiss();
					//Toast.makeText(getApplicationContext(), "Something wrong in your connection (1)", Toast.LENGTH_LONG).show();
				
				}
			}
			return null; 

				 
		}
		
		
		protected void onPostExecute(Void unused) {
			 
			
			result = json;
			

			//System.out.println("panjang");
			//System.out.println(result.length());
			//System.out.println(diskonba_list.size());
			diskonba_list.clear();
			//System.out.println("clear");
			//System.out.println(diskonba_list.size());

			if(code.equalsIgnoreCase("0")){
				
				Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
			}
			else{  
				try{
			      	JSONArray jArray = new JSONArray(result);
			      	JSONObject json_data=null;
			
			      	//System.out.println("array length");
			      	//System.out.println(jArray.length());
			      	
			       
			      	
			      	for(int i=0;i<jArray.length();i++){
						json_data = jArray.getJSONObject(i); 
						
						xml_merchant_photo = json_data.getString(KEY_MERCHANT_PHOTO);
						xml_merchant_name = json_data.getString(KEY_MERCHANT_NAME);
						xml_channel_name = json_data.getString(KEY_CHANNEL_NAME);
						xml_merchant_category = json_data.getString(KEY_MERCHANT_CATEGORY);
						xml_voucher_name = json_data.getString(KEY_VOUCHER_NAME);
						xml_transaction_id = json_data.getString(KEY_TRANSACTION_ID);
						xml_transaction_date = json_data.getString(KEY_TRANSACTION_DATE);
						xml_transaction_status = json_data.getString(KEY_TRANSACTION_STATUS);
						 
						 
			
						//System.out.println(xml_merchant_name); 
						//System.out.println(xml_channel_name); 
						//System.out.println(xml_merchant_category);
						//System.out.println(xml_voucher_name);
						//System.out.println(xml_transaction_id); 
						//System.out.println(xml_transaction_date);
						//System.out.println(xml_transaction_status);
						//System.out.println(xml_merchant_photo); 
						 
						if(Integer.parseInt(xml_transaction_status) <= 0)
						{
							sta = "Not yet used";
						}
						else if(Integer.parseInt(xml_transaction_status) >= 1)
						{
							sta = "Used";
						}
						else
						{
							sta = "Unknow";
						}
						
						//System.out.println("sta");
						//System.out.println(sta);
						HashMap<String, String> map = new HashMap<String, String>();
						//Element e = (Element) nl.item(i);
						// adding each child node to HashMap key => value
						
						Date date1, date2; 
						
						try {
							date1 = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(xml_transaction_date);
							SimpleDateFormat sdf1=new SimpleDateFormat("EEEE, dd MMMM yyyy");
							xml_transaction_date=sdf1.format(date1);
						} catch (java.text.ParseException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
			
						map.put(KEY_MERCHANT_NAME, xml_merchant_name);
						map.put(KEY_CHANNEL_NAME, "Channel : "+xml_channel_name);
						map.put(KEY_MERCHANT_CATEGORY, "Category" + xml_merchant_category); 
						map.put(KEY_VOUCHER_NAME, xml_voucher_name); 
						map.put(KEY_TRANSACTION_ID, xml_transaction_id);
						map.put(KEY_TRANSACTION_DATE, "Taken from : "+xml_transaction_date);
						map.put(KEY_TRANSACTION_STATUS,  sta);
						map.put(KEY_MERCHANT_PHOTO, Global.path + xml_merchant_photo);
			
						// adding HashList to ArrayList
						diskonba_list.add(map);
			      	}
		      	
				}catch(JSONException e1){ 
					System.out.println("catch 2");
					System.out.println(e1);
					Toast.makeText(getBaseContext(), "Something wrong in your connection (2)", Toast.LENGTH_LONG).show();
				}catch (ParseException e1){ 
					System.out.println("catch 3");
					System.out.println(e1);
					Toast.makeText(getBaseContext(), "Something wrong in your connection (3)", Toast.LENGTH_LONG).show();	
				} 
			}	 
			adapter = new LazyAdapter2(My_Voucher.this, diskonba_list); 

			actualListView.setAdapter(null);
			actualListView.setAdapter(adapter);
			
			pDialog.dismiss();
		}
	}
 
	
	
	
	
	
	
	
	
	 
	private class loadMoreListView extends AsyncTask<Void, Void, Void> {

		@Override
		protected void onPreExecute() {
			// Showing progress dialog before sending http request
			pDialog = new ProgressDialog(
					My_Voucher.this);
			pDialog.setMessage("Retrieve Data, Please wait...");
			pDialog.setIndeterminate(true);
			pDialog.setCancelable(false);
			pDialog.show();
		}

		protected Void doInBackground(Void... unused) {
			//runOnUiThread(new Runnable() {
			//	public void run() {
			// increment current page
			 
			current_page += 1;
			
			//ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
			
			String result = null;
			InputStream is = null;
			StringBuilder sb=null; 
	
			ArrayList nameValuePairs = new ArrayList();
			 
			// Next page request
			Global.URL = Global.link_my_voucher + session_userid + "&page=" + current_page;
			//System.out.println(Global.URL); 
			code="99";
			msg="Not connected to server";
			
			//System.out.println("Mulai do in background");
	 
			try{ 
				json=JSONfunctions.getStringContent(Global.URL);
				jsonobject=new JSONObject(json); 
				code=jsonobject.getString("code");
				msg=jsonobject.getString("msg");
				 
			}
			catch (Exception e) 
			{
				e.printStackTrace();
				System.out.println("catch code msg");
				System.out.println(e);
				//pDialog.dismiss();
				//Toast.makeText(getApplicationContext(), "Something wrong in your connection", Toast.LENGTH_LONG).show();
			
			}
			
			System.out.println("code "+code);
			if(code.equalsIgnoreCase("99")){
				try{ 
					System.out.println(Global.URL);
					//json=JSONfunctions.getStringContent2(Global.URL);
					System.out.println(json); 
					 
				}
				catch (Exception e) 
				{
					e.printStackTrace();
					System.out.println("catch 1");
					System.out.println(e);

					//pDialog.dismiss();
					//Toast.makeText(getApplicationContext(), "Something wrong in your connection (1)", Toast.LENGTH_LONG).show();
				
				}
			}
			return null;
  
		}
		
		
		protected void onPostExecute(Void unused) {
			// closing progress dialog

			//System.out.println("onpostexecute"); 
			count = 0; 
			//progressDoalog.dismiss(); 
			result = json;
			
			if(code.equalsIgnoreCase("0")){
				
				Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
			}
			else{
				try{
			      	JSONArray jArray = new JSONArray(result);
			      	JSONObject json_data=null;
		
			      	//System.out.println("array length");
			      	//System.out.println(jArray.length());
			      	
			      	for(int i=0;i<jArray.length();i++){
						json_data = jArray.getJSONObject(i); 
						
						xml_transaction_id = json_data.getString(KEY_TRANSACTION_ID);
						xml_transaction_date = json_data.getString(KEY_TRANSACTION_DATE);
						xml_transaction_image = json_data.getString(KEY_TRANSACTION_IMAGE);
						xml_transaction_status = json_data.getString(KEY_TRANSACTION_STATUS);
						xml_merchant_name = json_data.getString(KEY_MERCHANT_NAME);
						xml_merchant_category = json_data.getString(KEY_MERCHANT_CATEGORY);
						xml_merchant_photo = json_data.getString(KEY_MERCHANT_PHOTO);
						xml_voucher_name = json_data.getString(KEY_VOUCHER_NAME);
						xml_voucher_description = json_data.getString(KEY_VOUCHER_DESCRIPTION);
						xml_voucher_date = json_data.getString(KEY_VOUCHER_DATE);
						
						 
						
						//System.out.println(xml_transaction_id);
						//System.out.println(xml_transaction_date);
						//System.out.println(xml_transaction_image);
						//System.out.println(xml_transaction_status);
						//System.out.println(xml_merchant_name); 
						//System.out.println(xml_merchant_category);
						//System.out.println(xml_merchant_photo);
						//System.out.println(xml_voucher_name);
						//System.out.println(xml_voucher_description);
						//System.out.println(xml_voucher_date);
						 
						if(Integer.parseInt(xml_transaction_status) <= 0)
						{
							sta = "Not yet used";
						}
						else if(Integer.parseInt(xml_transaction_status) >= 1)
						{
							sta = "Used";
						}
						else
						{
							sta = "Unknow";
						}
						
						//System.out.println("sta");
						//System.out.println(sta);
						HashMap<String, String> map = new HashMap<String, String>();
						//Element e = (Element) nl.item(i);
						// adding each child node to HashMap key => value
						map.put(KEY_MERCHANT_NAME, xml_merchant_name);
						map.put(KEY_CHANNEL_NAME, "Channel : "+xml_channel_name);
						map.put(KEY_MERCHANT_CATEGORY, "Category : " + xml_merchant_category); 
						map.put(KEY_VOUCHER_NAME, xml_voucher_name); 
						map.put(KEY_TRANSACTION_ID, xml_transaction_id);
						map.put(KEY_TRANSACTION_DATE, "Taken : "+xml_transaction_date);
						map.put(KEY_TRANSACTION_STATUS,  sta);
						map.put(KEY_MERCHANT_PHOTO, Global.path + xml_merchant_photo);
		
						// adding HashList to ArrayList
						diskonba_list.add(map);
			      		}
			      	
				}catch(JSONException e1){ 
					System.out.println("catch 2");
					System.out.println(e1);
					Toast.makeText(getBaseContext(), "Something wrong in your connection (2)", Toast.LENGTH_LONG).show();
				}catch (ParseException e1){ 
					System.out.println("catch 3");
					System.out.println(e1);
					Toast.makeText(getBaseContext(), "Something wrong in your connection (3)", Toast.LENGTH_LONG).show();	
				} 
			
			}
			int currentPosition = actualListView.getFirstVisiblePosition();
			
			//System.out.println("getFirstVisiblePosition " + actualListView.getFirstVisiblePosition());
			//System.out.println("getFooterViewsCount " + actualListView.getFooterViewsCount());
			//System.out.println("getHeaderViewsCount " + actualListView.getHeaderViewsCount());
			//System.out.println("getLastVisiblePosition " + actualListView.getLastVisiblePosition());
			
			
			
			adapter = new LazyAdapter2(My_Voucher.this, diskonba_list); 
 
			actualListView.setAdapter(adapter);
					
			// Setting new scroll position
			//System.out.println("current" + currentPosition + 1);
			// Setting new scroll position
			//System.out.println("current" + currentPosition + 1);
			actualListView.setSelectionFromTop(currentPosition + 1, 0); 
			mPullRefreshListView.onRefreshComplete();	
			pDialog.dismiss();
		}
	}
	 

}